package tw.edu.tku.im.maze;

import org.json.JSONException;
import org.json.JSONObject;

public class Room {

   int roomID;
   String room;
   String homewoner;
   int currentUser;
   int mapLv ;
   int mode;
   boolean privateRoom;
   
   //-------------------------------------------------------
   public static Room parse(JSONObject jsonObj) throws JSONException {
      int roomID = jsonObj.getInt("roomID");
      String room = jsonObj.getString("room");
      String homewoner = jsonObj.getString("homewoner");
      int currentUser = jsonObj.getInt("currentUser");
      int mapLv = jsonObj.getInt("mapLv");
      int mode = jsonObj.getInt("mode");
      boolean privateRoom = jsonObj.getBoolean("privateRoom");
      return new Room(roomID, room, homewoner, currentUser, mapLv, mode, 
                          privateRoom);
   }
   
   //-------------------------------------------------------
   public Room(int roomID, String room, String homewoner, int currentUser,
                   int mapLv, int mode, boolean privateRoom) 
   {
      this.roomID = roomID;
      this.room = room;
      this.homewoner = homewoner;
      this.currentUser = currentUser;
      this.mapLv = mapLv;
      this.mode = mode;
      this.privateRoom = privateRoom;
   }
   
   
   //-------------------------------------------------------
   public int getRoomID() {
      return roomID;
   }

   public void setRoomID(int roomID) {
      this.roomID = roomID;
   }

   public String getRoom() {
      return room;
   }

   public void setRoom(String room) {
      this.room = room;
   }

   public String getHomewoner() {
      return homewoner;
   }

   public void setHomewoner(String homewoner) {
      this.homewoner = homewoner;
   }

   public int getCurrentUser() {
      return currentUser;
   }

   public void setCurrentUser(int currentUser) {
      this.currentUser = currentUser;
   }

   public int getMapLv() {
      return mapLv;
   }

   public void setMapLv(int mapLv) {
      this.mapLv = mapLv;
   }

   public int getMode() {
      return mode;
   }

   public void setMode(int mode) {
      this.mode = mode;
   }

   public boolean isPrivateRoom() {
      return privateRoom;
   }

   public void setPrivateRoom(boolean privateRoom) {
      this.privateRoom = privateRoom;
   }

   //-------------------------------------------------------
   public String toString() {
      StringBuilder ans = new StringBuilder("{ \"roomID\" : ");
      ans.append(roomID).append(", ").append("\"room\" : \"")
         .append(room).append("\", ").append("\"homewoner\" : \"")
         .append(homewoner).append("\", ").append("\"currentUser\" : ")
         .append(currentUser).append(", ").append("\"mapLv\" : ")
         .append(mapLv).append(", ").append("\"mode\" : ")
         .append(mode).append(", ").append("\"privateRoom\" : ")
         .append(privateRoom).append(" }");
      return ans.toString();
   }
   
   //-------------------------------------------------------
   public String toJSONString() throws JSONException {
      JSONObject room = new JSONObject();
      room.put("roomID", this.roomID);
      room.put("room", this.room);
      room.put("homewoner", this.homewoner);
      room.put("currentUser", this.currentUser);
      room.put("mapLv", this.mapLv);
      room.put("mode", this.mode);
      room.put("privateRoom", this.privateRoom);
      return room.toString();
   }
}
